package org.rbac.serv;

import org.rbac.po.PermissionGroups;
import org.rbac.vo.Group;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@Service
public class GroupServices extends CommonServices {
	/**
	 * 
	 * @Title: saveGroup 
	 * @Auther:KAN
	 * @Description: 组织机构保存 
	 * @param @param g
	 * @param @throws Exception 设定文件 
	 * @return void 返回类型 
	 * @throws
	 */
	@Transactional(timeout=20,propagation=Propagation.REQUIRED,rollbackFor=Exception.class)
	public void saveGroup(Group g) throws Exception {
			this.editGroup(g);
	}
	/**
	 * 
	 * @Title: moidifyGroup 
	 * @Auther:KAN
	 * @Description: 组织机构修改
	 * @param @param g
	 * @param @throws Exception 设定文件 
	 * @return void 返回类型 
	 * @throws
	 */
	@Transactional(timeout=20,propagation=Propagation.REQUIRED,rollbackFor=Exception.class)
	public void moidifyGroup(Group g) throws Exception {
		this.editGroup(g);
	}
	/**
	 * 
	 * @Title: editGroup 
	 * @Auther:KAN
	 * @Description: T组织机构修改
	 * @param @param g
	 * @param @throws Exception 设定文件 
	 * @return void 返回类型 
	 * @throws
	 */
	public void editGroup(Group g) throws Exception {
		if(null==g)return;
		PermissionGroups group = null;
		if (null==g.getId()) {
			//save
			group= new PermissionGroups();
			group.setGStatus((short)1);
		}else{
			group=(PermissionGroups) getDao().get(PermissionGroups.class, g.getId());
		}
		group.setGParent(g.getGParent());
		group.setGName(g.getGName());
		group.setGOrder(g.getGOrder());
		group.setGDeptno(g.getGDeptno());
		group.setGRemarks(g.getGRemarks());
		if (null==g.getId()) {
			getDao().save(group);
		}else{
			getDao().update(group);
		}
		
	}
	/**
	 * 
	 * @Title: deleteGroup 
	 * @Auther:KAN
	 * @Description: 组织机构删除
	 * @param @param id 删除id
	 * @return void 返回类型 
	 * @throws
	 */
	@Transactional(timeout=20,propagation=Propagation.REQUIRED,rollbackFor=Exception.class)
	public void deleteGroup(String id) {
		if(id!=null || !"".equals(id)){
			getDao().executeHQL(" UPDATE PermissionGroups SET GStatus=0 WHERE id=? ", Integer.parseInt(id.trim()));
		}
	}
	
	/**
	 * 
	 * @Title: deleteGroup 
	 * @Auther:KAN
	 * @Description: 组织机构删除
	 * @param @param id 删除id
	 * @return void 返回类型 
	 * @throws
	 */
	@Transactional(timeout=20,propagation=Propagation.REQUIRED,rollbackFor=Exception.class)
	public void disableGroup(String id) {
		if(id!=null || !"".equals(id)){
			getDao().executeHQL(" UPDATE PermissionGroups SET GStatus=2 WHERE id=? ", Integer.parseInt(id.trim()));
		}
	}

}
